home *** CD-ROM | disk | FTP | other *** search
/ FM Towns: Free Software Collection 11 / FM Towns Free Software Collection 11.iso / t_os / shell / watch / src / main.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-08-04  |  3.4 KB  |  207 lines

  1. /*
  2.     
  3.     WATCH   v1.4
  4.     
  5.         Programed by Keijiro Takahashi (novice)
  6.     
  7. */
  8.  
  9.  
  10. #include <stdio.h>
  11. #include <stdlib.h>
  12. #include <string.h>
  13. #include <winb.h>
  14. #include <te.h>
  15. #include <fntb.h>
  16. #include <gui.h>
  17. #include <egb.h>
  18. #include <guidbg.h>
  19. #include <eintm.h>
  20. #include <dlib.h>
  21.  
  22. #define rsmId "%%% DWATCHv1.4 %%%"
  23.  
  24.  
  25. extern void initIcn();
  26. extern void idleTask();
  27. int APL_init();
  28. int loadRsm();
  29.  
  30. extern MMIINIT    initDataBASE ;
  31. extern int h12Sw;
  32. char    *guiEgbPtr ;
  33. int     rsmx,rsmy,rsmSw;
  34.  
  35.  
  36.  
  37.  
  38.  
  39. /*
  40.  
  41.     Main
  42.  
  43. */
  44. void main()
  45. {
  46.     if(APL_init()==NOERR)
  47.     {
  48.         idleTask();
  49.         MMI_ExecSystem();
  50.     }
  51.     ICNTerm();
  52.     MMI_Close();
  53. }
  54.  
  55.  
  56.  
  57.  
  58. /*
  59.  
  60.     Initialize
  61.  
  62. */
  63. int APL_init()
  64. {
  65.  
  66.     int    ret ;
  67.     MMICTRL mmi;
  68.  
  69.     mmi.page0=SCREEN16 | SCREENIGNORE;
  70.     mmi.page1=SCREENUNUSED;
  71.     mmi.writePage=0;
  72.     mmi.displayPage=SCREENAVAILABLE;
  73.     mmi.priority=0;
  74.     mmi.mode=SCREENAVAILABLE;
  75.     mmi.width=SCREENEXPAND;
  76.     mmi.move.lupx=-16384;
  77.     mmi.move.lupy=-16384;
  78.     mmi.move.rdwx=16383;
  79.     mmi.move.rdwy=16383;
  80.     mmi.white=15;
  81.     mmi.black=8;
  82.     mmi.gray=7;
  83.     mmi.xor=7;
  84.     mmi.size=0;
  85.     mmi.ptr=NULL;
  86.     mmi.asize=0;
  87.     mmi.aptr=NULL;
  88.  
  89.     if ((ret = MMI_Open(&mmi)) != NOERR)        return ret ;
  90.  
  91.     if ((ret = MMI_initHyper()) < 0)            return ret ;
  92.     if ((ret = MMI_initDialogL40()) < 0)        return ret ;
  93.     if ((ret = MMI_initWindowL40()) < 0)        return ret ;
  94.     if ((ret = MMI_initMessageL40()) < 0)        return ret ;
  95.     if ((ret = MMI_initButtonL40()) < 0)        return ret ;
  96.     if ((ret = MMI_initDrawButtonL40()) < 0)    return ret ;
  97.     if ((ret = MMI_initIconL40()) < 0)            return ret ;
  98.  
  99.     if ((ret = MMI_Init(&initDataBASE)) < 0)    return ret ;
  100.  
  101.     guiEgbPtr = MMI_GetEgbPtr();
  102.     EIN_initGuiColor();
  103.  
  104.     if ((ret = ICNInit(0)) != 0)                return ret;
  105.     initIcn();
  106.  
  107.  
  108.     extern int shell();
  109.     MMI_SendMessage(MMI_GetBaseObj(),MM_SETEXEC,1,shell);
  110.     MMI_CallMessage(MMI_GetApliId(),GM_TITLE,
  111.             (int)"WATCH v1.3   By Keijiro",0);
  112.  
  113.     MMI_SetIdleTaskFunc(idleTask);
  114.  
  115.  
  116.     extern int baseWin;
  117.     
  118.     if (loadRsm())
  119.     {
  120.         MMI_SendMessage(baseWin,MM_MOVE,2,rsmx,rsmy);
  121.     }
  122.     else
  123.     {
  124.         WINCTRL    *pctrl;
  125.         MMI_GetControl(&pctrl);
  126.         MMI_SendMessage(baseWin,MM_MOVE,2,
  127.                     (pctrl->bound.rdwx-138)/2,(pctrl->bound.rdwy-101)/2);
  128.     }
  129.  
  130.  
  131.     MMI_SendMessage(MMI_GetBaseObj(),MM_SHOW,0);
  132.  
  133.     return NOERR ;
  134. }
  135.  
  136.  
  137.  
  138.  
  139.  
  140.  
  141. int loadRsm()
  142. {
  143.     char work[RSMWORKSIZE],buf[1024];
  144.     char *ptr;
  145.     int size;
  146.     
  147.     EIN_rsmInit(work,rsmId);
  148.     EIN_rsmBufSet(work,buf,1023);
  149.     
  150.     size = EIN_rsmLoad(work);
  151.     
  152.     if (size>0)
  153.     {
  154.         if ( (ptr=strstr(buf,"\nSWITCH: ")) != NULL )
  155.         {
  156.             if (sscanf(ptr,"\nSWITCH: %d\n",&h12Sw) > 0)
  157.             {
  158.                 rsmSw=h12Sw;
  159.             }
  160.         }
  161.         
  162.         if ( (ptr=strstr(buf,"\nMAINPOS: ")) != NULL )
  163.         {
  164.             if (sscanf(ptr,"\nMAINPOS: %d %d\n",&rsmx,&rsmy) > 1)
  165.             {
  166.                 return(1);
  167.             }
  168.         }
  169.     }
  170.  
  171.     return(0);
  172. }
  173.  
  174.  
  175.  
  176.  
  177.  
  178.  
  179. void saveRsm()
  180. {
  181.     extern int baseWin;
  182.     HYPER hyp;
  183.     
  184.     MMI_SendMessage(baseWin,MM_GETHYPER,1,&hyp);
  185.     
  186.     if ( (rsmx!=hyp.fr.lupx) || (rsmy!=hyp.fr.lupy) || (rsmSw!=h12Sw) )
  187.     {
  188.         char work[RSMWORKSIZE],buf[1024];
  189.         char aplpath[128];
  190.         
  191.         EIN_rsmInit(work,rsmId);
  192.         EIN_rsmBufSet(work,buf,1023);
  193.         
  194.         MMI_CallMessage(MMI_GetApliId(),GM_QUERYID,QM_PATH,(int)aplpath );
  195.         
  196.         EIN_rsmBufPrintf(work,"APLPATH: %s",aplpath);
  197.         EIN_rsmBufCat    (work,"TITLE:   WATCH v1.4");
  198.         EIN_rsmBufCat    (work,"COMMENT: スタンダードな時計");
  199.         EIN_rsmBufPrintf(work,"SWITCH: %d",h12Sw);
  200.         EIN_rsmBufPrintf(work,"MAINPOS: %d %d",hyp.fr.lupx,hyp.fr.lupy);
  201.         EIN_rsmBufTail(work);
  202.         EIN_rsmSave(work);
  203.     }
  204.  
  205.     return;
  206. }
  207.